#!/bin/bash
# author:zyw date:2021-12-18
read -p "请输入要安装服务路径与.env SERVER_ROOT_PATH保持一致:" server_root_path
if [[ $server_root_path == "q" ]];then
  echo "退出成功!"
  exit
fi
#php=(1,2,3,4,5)
#if [[ ! "${php[*]}" =~ $php_version ]]; then
#   echo "请选择php版本"
#   exit
#fi
#case $php_version in
#1)
#   php_version=56
#   ;;
#2)
#   php_version=71
#   ;;
#3)
#   php_version=72
#   ;;
#4)
#   php_version=73
#   ;;
#5)
#   php_version=74
#  ;;  
#*)
#  echo "error php version"
#  exit
#esac
php_version=7.3
# mysql
[[ ! -d $server_root_path ]] &&  mkdir -p $server_root_path
[[ ! -d "$server_root_path/mysql" ]] &&  mkdir -p "$server_root_path/mysql"
[[ ! -d  "$server_root_path/mysql/conf" ]] &&  mkdir -p "$server_root_path/mysql/conf"
[[ ! -d "$server_root_path/mysql/data" ]] &&  mkdir -p "$server_root_path/mysql/data"
# nginx
[[ ! -d "$server_root_path/nginx" ]] &&  mkdir -p "$server_root_path/nginx"
[[ ! -d  "$server_root_path/nginx/conf" ]] &&  mkdir -p "$server_root_path/nginx/conf"
[[ ! -d "$server_root_path/nginx/sites" ]] &&  mkdir -p "$server_root_path/nginx/sites"
[[ ! -d "$server_root_path/nginx/ssl" ]] &&  mkdir -p "$server_root_path/nginx/ssl"
# php
[[ ! -d  "$server_root_path/php/$php_version" ]] &&  mkdir -p "$server_root_path/php/$php_version"
[[ ! -d  "$server_root_path/php/$php_version/conf" ]] &&  mkdir -p "$server_root_path/php/$php_version/conf"
[[ ! -d  "$server_root_path/php/$php_version/log/php" ]] &&  mkdir -p "$server_root_path/php/$php_version/log/php"
[[ ! -d  "$server_root_path/php/$php_version/log/php-fpm" ]] &&  mkdir -p "$server_root_path/php/$php_version/log/php-fpm"
# mongo
[[ ! -d  "$server_root_path/mongo/data" ]] &&  mkdir -p "$server_root_path/mongo/data"
[[ ! -d  "$server_root_path/mongo/conf" ]] &&  mkdir -p "$server_root_path/mongo/conf"
[[ ! -d  "$server_root_path/mongo/log" ]]  &&  mkdir -p "$server_root_path/mongo/log"
# redis

[[ ! -d  "$server_root_path/redis/data" ]] &&  mkdir -p "$server_root_path/redis/data"
[[ ! -d  "$server_root_path/redis/conf" ]] &&  mkdir -p "$server_root_path/redis/conf"
[[ ! -d  "$server_root_path/redis/log" ]] &&  mkdir -p "$server_root_path/redis/log"

now_path=$('pwd')
# 复制指定配置文件到创建目录
cp -rf $now_path/mysql/conf/* $server_root_path/mysql/conf/
cp -rf $now_path/php-fpm/$php_version/*  $server_root_path/php/$php_version/conf/
cp "$now_path/nginx/nginx.conf"   "$server_root_path/nginx/conf/"
cp "$now_path/redis/conf/redis.conf"  "$server_root_path/redis/conf/"
cp "$now_path/mongo/conf/mongo.conf"  "$server_root_path/mongo/conf/mongo.conf"
chmod 775 -R $server_root_path/mysql
